package com.hyb.algorithm.data.struct.dp;

/**
 * @author: ybhu
 * @create: 2021/08/25 07:47
 */
public class StoneGame2 {


    public static void main(String[] args) {

        int[] piles = new int[]{3, 9, 1, 2};
        StoneGame2 exec = new StoneGame2();
        System.out.println(exec.stoneGame(piles));
    }

    /**
     * piles=[3,9,1,2]
     *
     * @param piles
     * @return
     */
    public int stoneGame(int[] piles) {
        int n = piles.length;

        if (n <= 0) {
            return 0;
        }

        StonePair[][] dp = new StonePair[n][n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.println(String.format("i=%s,j=%s", i, j));
                dp[i][j]=new StonePair();
                dp[i][j].first = 0;
                dp[i][j].second = 0;
            }
        }

        //dp[i][j] 代表的是  piles[i...j] 的中先手和后手的最大值
        //比如  dp[0,1]  就是[3,9]={9,3}  先手拿9  后手只能拿3
        for (int i = 0; i < n; i++) {
            dp[i][i].first = i;
            dp[i][i].second = 0;
        }

        //斜着遍历数组
        for (int l = 2; l < n; l++) {
            for (int i = 0; i < n - l; i++) {
                int j = l + i - 1;
                System.out.println(String.format("i=%s,j=%s", i, j));
            }
        }

        return dp[0][n - 1].first;
    }
}
